package com.hex.liyue.usermodule.activity;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.widget.MediaController;
import android.widget.VideoView;

import com.hex.liyue.R;

/**
 * Created by $cmm on 2016/7/11.
 *
 * 全屏播放视频的界面
 */
public class VideoActivity extends Activity {
    private VideoView videoView;
    private Uri mUri;
    private int mPositionWhenPaused;
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);// 设置成全屏模式
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);// 强制为横屏
        setContentView(R.layout.activity_video);
        String url=getIntent().getStringExtra("video");
//        String url = "http://videofile.xxxx.cn/Upload/Video/File/20140411/201404110228168972.mp4";
        // String url =
        // "http://player.youku.com/player.php/sid/XNDYwOTEzNzQ4/v.swf";

        mUri = Uri.parse(url);
        videoView = (VideoView) findViewById(R.id.video_videoView);
        MediaController mediaController = new MediaController(this);
        videoView.setMediaController(mediaController);

        // videoView.setVideoPath("/sdcard/xyx.3gp");
        // videoView.setVideoURI(mUri);
        // videoView.requestFocus();
        // videoView.start();

    }

    public void onStart()
    {
        // Play Video
        videoView.setVideoURI(mUri);
        videoView.start();

        super.onStart();
    }

    public void onPause()
    {
        // Stop video when the activity is pause.
        mPositionWhenPaused = videoView.getCurrentPosition();
        videoView.stopPlayback();

        super.onPause();
    }

    public void onResume()
    {
        // Resume video player
        if (mPositionWhenPaused >= 0)
        {
            videoView.seekTo(mPositionWhenPaused);
            mPositionWhenPaused = -1;
        }

        super.onResume();
    }

    public boolean onError(MediaPlayer player, int arg1, int arg2)
    {
        return false;
    }

    public void onCompletion(MediaPlayer mp)
    {
        this.finish();
    }

}
